<div event-click="{{'$Event.closeContent'}}" class="goodscontent {{isContent&&'focus'}}">
    <div class="back">
        <sbutton shadownum1="0 1px 4px 0" shadownum2="0 1px 8px 0" class="btn" text="返回"></sbutton>
    </div>
    <div class="detailcontent"></div>
</div>
<div class="checkAdd {{checkAdd&&'focus'}}" event-click="{{'$Event.checkAdd'}}">
    {{#if loginer}}
        <div>成功添加商品</div>
        <div>
            <a href="mobile.main.html#default/cart"><button>转到购物车</button></a>
            <button>留在此页</button>
        </div>
    {{#else}}
        <div>您还未登陆</div>
        <div>
            <a href="mobile.main.html#default/sign_in?cb_url=1"><button>去登陆</button></a>
            <button>取消</button>
        </div>
    {{/if}}
</div>
<div class="goods_details">
    <goodsimgview></goodsimgview>
    <div class="goodsinfo">
        <div class="titlebar">
            商品信息
            <div class="i icon-sina-weibo" event-click="{{'$Event.shareToWeibo'}}"></div>
                <div class="i icon-qq" event-click="{{'$Event.shareQzone'}}"></div>
        </div>
        <hr />
        <div class="infobox">
            <div class="intro">
                {{#if goods_detail.intro}}
                    {{goods_detail.intro}}
                {{/if}}
                {{#if goods_detail.detail_content}}
                    <div><sbutton class="btn" shadownum1="0 1px 4px 0" shadownum2="0 1px 8px 0" text="查看更多详情" event-click="{{'$Event.open_goods_content'}}"></sbutton></div>
                {{#else}}
                <p>此商品没有添加详细描述</p>
                {{/if}}
            </div>
        </div>
        <hr />
        <div class="saleinfo">
            <div class="item">状态：{{#if goods_detail.num==0}}缺货{{#else}}有货（{{goods_detail.num}}）{{/if}}</div>
            <div class="item">销量：{{goods_detail.sale_num}}</div>
        </div>
    </div>
    <div class="bottomblock"></div>
    <div class="floatbtnbox">
        <a event-click="{{'$Event.closeContent'}}"><div class="back {{isContent&&'focus'}}">返回</div></a>
        数量：
        <input class="num" type="text" value="1" bind-input="{{'$Cache.goods_details.buy_number'}}" />
        {{#if goods_detail.num }}
        <a>
            <sbutton shadownum1="0 0 10px 2px" shasownum2="0 0 6px 2px" class="btn" event-click="{{'$Event.goods.add_to_cart'}}" text="加入购物车" event-click-new="{{$Event.checkAdd}}"></sbutton>
        </a>
        {{#else}}
        <a>
            <sbutton shadownum1="0 0 10px 2px" shasownum2="0 0 6px 2px" class="btn disabled" disabled="true" text="暂时缺货"></sbutton>
        </a>
        {{/if}}
    </div>
</div>


<xmp type="tag" name="goodsimgview">
    <div class="goodsimg">
        <div class="bigbox">
            <div class="movebox">
                {{#if goods_detail.detail_img_urls.length}} {{#each goods_detail.detail_img_urls}}
                <img class="bigimg" bind-src="{{$This}}" />{{/each}} {{#else}}
                <img class="bigimg" src="images/imgerror.jpg" />{{/if}}
            </div>
            <div class="pricebox">
                <div class="itemleft">￥{{goods_detail.price_toFixed_2+"/"+goods_detail.unit}}</div>
                <div class="itemright">
                    <a event-click="{{'$Event.goods.collect_toggle'}}" class="{{$Cache.goods_detail.is_collect&&'icon-star3'||'icon-star'}}">{{$Cache.goods_detail.is_collect&&'已收藏'||'点击收藏'}}</a>
                </div>
            </div>
        </div>
        <div class="smallbox">
            {{#if goods_detail.detail_img_urls.length}} {{#each goods_detail.detail_img_urls }}
            <img name="{{$Index}}" class="smallimg" bind-src="{{$This}}?imageView/1/w/50/h/50" />{{/each}} {{#else}}此商品卖家没有上传图片{{/if}}
        </div>
    </div>
    <script type="text/vm">
        function(vm){ var movebox=vm.queryElement({ className:"movebox" })[0]; require(['jQuery'],function(){ var w=$(movebox).width(); $('.smallbox').on("click","img",function() { $(movebox).stop().animate({ marginLeft: -w * $(this).attr('name') }, 350); }) }) }
    </script>
</xmp>


 <script type="text/vm">
    function(vm) {
        require(['common','jQuery'], function(jSouper,$) {
            // 分享
            var title,pic,rLink,site,summary;
            function getinfo(){
                title='我觉得#'+App.get('goods_detail.goods_name')+'#不错，跟大家分享一下',
                pic=App.get("goods_detail.preview_img_url")+"?imageView/1/w/100/h/100",
                rLink = location.href+"&rcid"+App.get('loginer._id'),
                site=location.host,
                summary=App.get('intro');
            }
            // 微博
            App.set('$Event.shareToWeibo',function(){
                getinfo();
                window.open("http://service.weibo.com/share/share.php?pic=" + encodeURIComponent(pic) + "&title=" +encodeURIComponent(title.replace(/&nbsp;/g, " ").replace(/<br \/>/g, " ")) + "&url=" + encodeURIComponent(rLink),
                    "分享至新浪微博",
                    "toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no");
            });
            // qq空间
            App.set('$Event.shareQzone',function(){
                window.open('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?title='+  
                   encodeURIComponent(title)+'&url='+encodeURIComponent(rLink)+'&summary='+  
                   encodeURIComponent(summary)+ '&site='+encodeURIComponent(site)  
                   ,'_blank','scrollbars=no,status=no,resizable=yes'); 
            });

            var meta1=document.createElement('meta');
            meta1.content="width=device-width, initial-scale=1.0, maximum-scale=3.0, user-scalable=yes";
            meta1.name="viewport";
            var meta2=document.createElement('meta');
            meta2.content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no";
            meta2.name="viewport";
            App.set('$Event.checkAdd',function(){
                App.model.toggle('checkAdd');
            });
            App.set('$Event.open_goods_content',function(){
                App.model.toggle('isContent');
                // document.head.appendChild(meta1);
                $('.detailcontent').html(App.get('goods_detail.detail_content'));
            });
            App.set('$Event.closeContent',function(){
                // document.head.removeChild(meta1);
                // document.head.appendChild(meta2);
                App.model.toggle('isContent');
                document.head.removeChild(meta2);
            })
        });
    }
</script>